﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using MultiPhotoChooserExample.Resources;
using MultiPhotoChooser;
using Coding4Fun.Toolkit.Controls;
using System.Windows.Media.Imaging;

namespace MultiPhotoChooserExample
{
    public partial class MainPage : PhoneApplicationPage
    {
        MultiPhotoChooserTask task = new MultiPhotoChooserTask();
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            Loaded += MainPage_Loaded;
            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            task.SelectionLimit = 10;
            task.OnComplete += task_OnComplete;
        }

        void task_OnComplete(object sender, MultiPhotoResult e)
        {
            if (lls_photolist.ItemsSource != null)
                lls_photolist.ItemsSource = null;

            lls_photolist.ItemsSource = e.ChosenPhotoList;
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (task.IsOpen)
            {
                task.Close();
                e.Cancel = true;
            }
        }

        private void btnShowChooser_Click(object sender, RoutedEventArgs e)
        {
            task.Show();
        }
    }
}